<template>
  <div class="container">
    <el-row :gutter="20">
      <el-col :span="12" :offset="0">
        <el-form :model="formList" ref="formList" :rules="rules" size="normal">
          <el-form-item label="旧密码" prop="oldpassword">
            <el-input v-model="formList.oldpassword"></el-input>
          </el-form-item>
          <el-form-item label="新密码" prop="newpassword">
            <el-input v-model="formList.newpassword"></el-input>
          </el-form-item>
          <el-form-item label="确认密码" prop="repassword">
            <el-input v-model="formList.repassword"></el-input>
          </el-form-item>
        </el-form>
        <div class="center">
          <el-button type="primary" @click="save" :loading="loading">修改</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  name: '',
  components: {

  },
  props: {

  },
  data () {
    return {
      loading: false,
      formList: {},
      rules: {
        oldpassword: [
          { required: true, message: '请填写旧密码', trigger: 'blur' }
        ],
        newpassword: [
          { required: true, validator: this.$util.isPsd, trigger: 'blur' }
        ],
        repassword: [
          { required: true, validator: this.$util.isPsd, trigger: 'blur' }
        ],
      }
    }
  },
  created () {

  },
  mounted () {
  },
  methods: {
    async save () {
      if (this.formList.newpassword != this.formList.repassword) {
        this.$tips.error('密码两次输入不一致')
        return false
      }
      this.$refs['formList'].validate(async (valid) => {
        if (valid) {
          this.loading = true
          const res = await this.$http('sysUpPsd', {
            ...this.formList
          })
          if (res.errcode === 9999) {
            this.$tips.error(res.errmsg)
          } else {
            this.$tips.success(res.errmsg)
          }
          this.loading = false
          //! 成功后引导至登录页面，有空再写
        } else {
          this.$tips.error('请检查必填项')
          this.loading = false
        }
      })
    }
  },
  computed: {

  }
}
</script>
<style lang='scss' scoped>
</style>
